package com.qiyun.dinghuohui.utils;

import com.qiyun.dinghuohui.common.CommonDataSets;

import java.util.Comparator;
import java.util.Map;

public class OrderSortDataByCode implements Comparator<Map<String, Object>> {

	private boolean shengXu = false;

	public OrderSortDataByCode() {
	};

	public OrderSortDataByCode(boolean shengXu) {
		this.shengXu = shengXu;
	}

	@Override
	public int compare(Map<String, Object> lhs, Map<String, Object> rhs) {
		try {
			int numOne = CommonDataSets.getIntforString(lhs.get("code").toString());
			int numTwo = CommonDataSets.getIntforString(rhs.get("code").toString());
			if (numOne > numTwo) {
				if (shengXu) {
					return 1;
				} else {
					return -1;
				}
			} else if (numOne < numTwo) {
				if (shengXu) {
					return -1;
				} else {
					return 1;
				}
			} else {
				return 0;
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		return 0;
	}
}
